import type { DynamicProps } from '/#/utils';
import type { BasicTableProps, BasicColumn } from '/@/components/Table/src/types/table';
import { FormProps } from '/@/components/Table';
import { searchSchemas } from './searchData';
import { getDriveLog } from '/@/api/sys/gateway/gateway';
import moment from 'moment';
type Props = Partial<DynamicProps<BasicTableProps>>;
// 列配置
const tableColumns: BasicColumn[] = [
  {
    title: '时间',
    dataIndex: 'time',

    width: 120,
  },
  {
    title: '设备名称',
    dataIndex: 'device_name',

    width: 120,
  },
  {
    title: '驱动名称',
    dataIndex: 'drive_name',

    width: 120,
  },
  {
    title: '数据日志',
    dataIndex: 'message',

    width: 120,
  },
];

export const formConfig: Partial<FormProps> = {
  labelWidth: 70,
  labelAlign: 'right',
  schemas: searchSchemas,
  actionColOptions: {
    span: 5,
    style: { textAlign: 'right', marginLeft: '0px' },
  },
};

export const tableConfig: Props = {
  api: getDriveLog,
  fetchSetting: {
    //配置数据data名称
    listField: 'list',
    totalField: 'total',
    sizeField: 'page_size',
  },
  beforeFetch: (formModel) => {
    formModel.device_name = JSON.parse(localStorage.getItem('deviceinfo')).name;
    if (formModel.time) {
      formModel.start_time =
        formModel.time.length == 0
          ? undefined
          : moment(formModel.time[0]).format('YYYY-MM-DD HH:mm:ss');
      formModel.end_time =
        formModel.time.length == 0
          ? undefined
          : moment(formModel.time[1]).format('YYYY-MM-DD HH:mm:ss');
    }
  },
  columns: tableColumns,
  useSearchForm: true,
  formConfig: formConfig,
  showTableSetting: true,
  tableSetting: { fullScreen: true },
  // rowKey: 'id',
  bordered: true,
  actionColumn: {
    width: 60,
    title: '操作',
    slots: { customRender: 'operation' },
  },
};
